#include <gtest/gtest.h>

#include "utils/dbutils.hpp"
#include "utils/kvutils.hpp"
#include "utils/testutils.hpp"

std::vector<std::string> vals;

#define NUM_OF_THREAD 8

class TestKV : public testing::Test {
 protected:
  static void SetUpTestCase() {
    std::cout << "set up TestKV" << std::endl;
    KVWrapper::GetInstance("test")->Init();
  }
  static void TearDownTestCase() {
    std::cout << "tear down TestKV" << std::endl;
  }
}

TEST_F(TestKV, TestKV) {
  auto TestFunc = [] {
    auto random_key = RandomString(100);
    auto random_value = RandomString(200);
    KVWrapper::GetInstance()->Put(random_key, random_value);
    auto test_value = KVWrapper::GetInstance()->Get(random_key);
    EXPECT_EQ(random_value, test_value);
    EXPECT_FALSE(KVWrapper::GetInstance()->Exist(RandomString(200)));
  };
  for (int i = 0; i < NUM_OF_THREAD; ++i) {
    pthread_create(nullptr, nullptr, &TestFunc, nullptr)
  }
}

class TestDB : public testing::Test {
 protected:
  static void SetUpTestCase() {
    std::cout << "set up TestDB" << std::endl;
    DBWrapper::GetInstance("test")->Init();
  }
  static void TearDownTestCase() {
    std::cout << "tear down TestDB" << std::endl;
  }
}

TEST_F(TestDB, TestDB) {
  auto TestFunc = [] {
    std::vector<std::string> random_row = {RandomString(100),
                                           RandomString(200)};
    DBWrapper::GetInstance()->Insert(random_row);
    auto result = DBWrapper::GetInstance()->Select(
        "select * from test where key = " + random_row[0] + ";");
    EXPECT_EQ(random_row, result->at(0));
  };
  for (int i = 0; i < NUM_OF_THREAD; ++i) {
    pthread_create(nullptr, nullptr, &TestFunc, nullptr)
  }
}

int main() { return 0; }